using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
//ok

namespace WCFDicing.DataContracts
{
    /// <summary>
    /// klasa opisujaca gracza grajacego w kosci
    /// </summary>
    [System.Runtime.Serialization.DataContractAttribute( Namespace = "http://WCFDicing.DataContracts/2008/01", Name = "DicingPlayer" )]
    public class DicingPlayer
    {

        #region Fields+Get

        /// <summary>
        /// id gracza
        /// </summary>
        private int playerId;

        /// <summary>
        /// get i set id gracza
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "PlayerId", Order = 0 )]
        public int PlayerId
        {
            get { return playerId; }
            set { playerId = value; }
        }
        
        /// <summary>
        /// ile pieniedzy obstawil
        /// </summary>
        private int actualBetField;

        /// <summary>
        /// get i set ile pieniedzy obstawil
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "ActualBetField", Order = 1 )]
        public int ActualBetField
        {
            get { return actualBetField; }
            set { actualBetField = value; }
        }

        /// <summary>
        /// ile pieniedzy ma aktualnie
        /// </summary>
        private int moneyField;

        /// <summary>
        /// get i set ile pieniedzy ma aktualnie
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "MoneyField", Order = 2 )]
        public int MoneyField
        {
            get { return moneyField; }
            set { moneyField = value; }
        }

        /// <summary>
        /// aktualna akcja gracza
        /// </summary>
        private DicingActionList currentAction;

        /// <summary>
        /// get i set aktualna akcja gracza
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "CurrentAction", Order = 3 )]
        public DicingActionList CurrentAction
        {
            get { return currentAction; }
            set { currentAction = value; }
        }

        /// <summary>
        /// cel gracza (gdy gracz rozgrywa gre)
        /// </summary>
        private int aim;

        /// <summary>
        /// get i set cel gracza (gdy gracz rozgrywa gre)
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "Aim", Order = 4 )]
        public int Aim
        {
            get { return aim; }
            set { aim = value; }
        }

        /// <summary>
        /// aktualny numer proby wyrzucenia celu 
        /// </summary>
        private int currentThrowNo;

        /// <summary>
        /// get i set aktualny numer proby wyrzucenia celu 
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "CurrentThrowNo", Order = 5 )]
        public int CurrentThrowNo
        {
            get { return currentThrowNo; }
            set { currentThrowNo = value; }
        }
        
        /// <summary>
        /// id krzesla na ktorym siedzi gracz
        /// </summary>
        private int chairId;

        /// <summary>
        /// get i set id krzesla na ktorym siedzi gracz
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "ChairId", Order = 6 )]
        public int ChairId
        {
            get { return chairId; }
            set { chairId = value; }
        }

        private string name;

        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "Name", Order = 7 )]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// konstruktor domyslny
        /// </summary>
        public DicingPlayer() { }

        /// <summary>
        /// konstruktor z nadanym id gracz, id krzesla i ilosci pieniedzy
        /// </summary>
        /// <param name="playerId">id gracza</param>
        /// <param name="chairId">id zajetego krzesla</param>
        /// <param name="money">ilosc pieniedzy</param>
        public DicingPlayer( int playerId, int chairId, int money )
        {
            moneyField = money;
            this.playerId = playerId;
            this.chairId = chairId;
            currentAction = DicingActionList.NewRound;
        }

        /// <summary>
        /// konstruktor z nadanym id gracz, id krzesla i ilosci pieniedzy
        /// </summary>
        /// <param name="playerId">id gracza</param>
        /// <param name="chairId">id zajetego krzesla</param>
        /// <param name="money">ilosc pieniedzy</param>
        /// <param name="name">nazwa uzytkownika</param>
        public DicingPlayer( int playerId, int chairId, int money, string name )
        {
            moneyField = money;
            this.playerId = playerId;
            this.chairId = chairId;
            this.name = name;
            currentAction = DicingActionList.NewRound;
        }

        #endregion

        #region Functions

        /// <summary>
        /// ustala kwote zakladu
        /// </summary>
        /// <param name="betCash">stawka zakladu</param>
        public void Bet( int betCash )
        {
            actualBetField = betCash;
            moneyField = moneyField - actualBetField;      //odejmujemy kase z konta
            currentAction = DicingActionList.Wait;          //czekamy na dalsza rozgrywke
        }

        /// <summary>
        /// obsluga przegranej gracza
        /// </summary>
        public void Loose()
        {
            //actualBetField = 0;
            currentAction = DicingActionList.Lost;
        }

        /// <summary>
        /// obsluga wygranej gracza
        /// </summary>
        public void Win()
        {
            moneyField += 2 * actualBetField;   
            //actualBetField = 0;
            currentAction = DicingActionList.Win;
        }
        
        /// <summary>
        /// obsluga spasowania
        /// </summary>
        public void Pass()
        {
            //nie uzywane
            currentAction = DicingActionList.Pass;
            this.actualBetField = 0;
        }

        /// <summary>
        /// przygotowuje gracza na nastepna runde
        /// </summary>
        public void PrepareForNewRound()
        {
            currentAction = DicingActionList.NewRound;
            actualBetField = 0;
            this.aim = 0;
            this.currentThrowNo = 0;
        }

        #endregion
    }
}
